package ru.agiledev.aos.frontend.client.panel;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HorizontalPanel;
import ru.agiledev.aos.frontend.shared.TransformationResult;

/**
 * Created by a.kirillov
 * Date: 2/24/12 Time: 6:14 PM
 */
public class InfoPanel extends HorizontalPanel {
    private Anchor transform;
    private TransformationResultDialog dialog = new TransformationResultDialog();
    private AboutDialog about = new AboutDialog();

    public InfoPanel(){
        Anchor info = new Anchor("Как это работает?");
        info.addClickHandler(new ClickHandler(){
            @Override
            public void onClick(ClickEvent clickEvent) {
               about.show();
            }
        });
        info.setStyleName("info");

        HorizontalPanel strut = new HorizontalPanel();
        strut.setWidth("363px");
        strut.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);

        transform = new Anchor("Запрос преобразован");
        transform.addClickHandler(new ClickHandler(){
            @Override
            public void onClick(ClickEvent clickEvent) {
                dialog.center();
                dialog.show();
            }
        });
        transform.setVisible(false);
        transform.setStyleName("info");
        strut.add(transform);


        add(info);
        add(strut);
    }

    public void enableTransform(){
        transform.setVisible(true);
    }

    public void disableTransform(){
        transform.setVisible(false);
    }

    public void setResults(TransformationResult result){
        enableTransform();
        dialog.getTransformResultsPanel().setResults(result);
    }

    public void clearResults(){
        disableTransform();
        dialog.getTransformResultsPanel().clearResults();
    }
}
